package com.yzh.homework;

/**
 * @author 于振晗
 * @title: Recursion
 * @description: TODO 递归
 * @date 2020年09月01日
 * @path com.yzh
 */
public class Recursion{
    public static void main(String[] args) {
        int fei = fei(6);
        System.out.println("斐波那契数列"+fei);
        int fac = fac(3);
        System.out.println("阶乘"+fac);
    }
    //factorial阶乘
    public static int fac(int n){
        if(n == 1){
            return 1;
        }else{
            return n*(n-1);
        }
    }
    //斐波那契数列
    public static int fei(int n){
        if(n ==1 || n == 2){
            return 1;
        }else{
            return fei(n-1)+fei(n-2);
        }
    }
}
